{extend name="layout/base" /}
<!-- 标题 -->
{block name="title"}管理列表{/block}
<!-- CSS -->
{block name="css"}{/block}

<!-- 具体内容 -->
{block name="content"}
<h2 class="header-dividing">管理列表 <small>User manage</small></h2>
<div class="navbar navbar-default navbar-content">
    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
            {if(check_auth('manage-create'))}<li><a data-toggle="modal" data-target="#modal-create" data-action="{:url('@admin/manage/save')}"> <i class="icon icon-plus"></i> 添加管理员</a></li>{/if}
            {if(check_auth('manage-group'))}<li><a href="{:url('@admin/manage/group')}"> <i class="icon icon-group"></i> 用户分组</a></li>{/if}
        </ul>
        <!-- 导航中的表单 -->
        <form class="navbar-form navbar-left" role="search" method="get" action="{:url('@admin/manage')}">
            <input type="text" class="form-control" name="keywords" placeholder="搜索" value="{$keywords}" required>
            <button type="submit" class="btn btn-default">搜索</button>
        </form>
    </div>
</div>
<div class="panel">
    <table class="table datatable table-fixed" data-checkable="true" data-check-by-click-row="false" data-fixed-left-width="200" data-fixed-right-width="320">
        <thead>
            <tr>
                <th data-width="50">ID</th>
                <th data-width="100">帐号</th>
                <th class="flex-col" data-width="100">用户组</th>
                <th class="flex-col" data-width="120">姓名</th>
                <th class="flex-col" data-width="150">手机</th>
                <th class="flex-col" data-width="180">邮箱</th>
                <th class="flex-col" data-width="150">登录IP</th>
                <th class="flex-col" data-width="180">登录时间</th>
                <th class="flex-col" data-width="100">登录次数</th>
                <th data-width="80" class="text-center">状态</th>
                <th data-width="80" class="text-center">修改</th>
                <th data-width="80" class="text-center">密码</th>
                <th data-width="80" class="text-center">删除</th>
            </tr>
        </thead>
        <tbody>
            {volist name="list" id="vo"}
            <tr data-id="{$vo['manage_id']}">
                <td>{$vo['manage_id']}</td>
                <td>{$vo['manage_username']}</td>
                <td>{$vo->group->group_name}</td>
                <td>{$vo['manage_fullname']}</td>
                <td>{$vo['manage_phone']}</td>
                <td>{$vo['manage_email']}</td>
                <td>{$vo['manage_login_ip']}</td>
                <td>{$vo['manage_login_time']}</td>
                <td>{$vo['manage_login_num']} 次</td>
                <td class="text-center">{$vo['manage_status_html']|raw}</td>
                <td class="text-center">{if(check_auth('manage-edit'))}<a data-toggle="modal" data-target="#modal-create" data-url="{:url('@admin/manage/edit', 'id='.$vo['manage_id'])}" data-action="{:url('@admin/manage/update')}">修改</a>{/if}</td>
                <td class="text-center">{if(check_auth('manage-reset'))}<a class="manage-repwd" data-url="{:url('@admin/manage/repwd')}" data-id="{$vo['manage_id']}">重置</a>{/if}
                </td>
                <td class="text-center">{if(check_auth('manage-delete'))}<a class="delete" data-url="{:url('@admin/manage/delete','id='.$vo['manage_id'])}">删除</a>{/if}</td>
            </tr>
            {/volist}
        </tbody>
    </table>
    {empty name="list"}
    <div class="mb20 mt20 text-center">
        {if ($keywords!='')}
            未搜索到 “{$keywords}” 相关的用户 &nbsp; <a href="{:url('@admin/manage')}">查看全部用户</a>
        {else /}
            暂未添加用户
        {/if}
    </div>
    {/empty}
    {notempty name="list"}
    <div class="mb10 ml10">
        {if(check_auth('manage-delete'))}
            <button class="btn btn-danger check-delete" type="button" data-url="{:url('@admin/manage/delete')}">删除帐号</button>
        {/if}
        {if(check_auth('manage-checked'))}
            <button class="btn btn-info check-checked" type="button" data-url="{:url('@admin/manage/checked')}">审核帐号</button>
        {/if}
        {if(check_auth('manage-disable'))}
            <button class="btn btn-warning check-disable" type="button" data-url="{:url('@admin/manage/disable')}">禁用帐号</button>
        {/if}
        {if(check_auth('manage-disable'))}
            <button class="btn btn-success check-enable" type="button" data-url="{:url('@admin/manage/enable')}">启用帐号</button>
        {/if}
    </div>
    {/notempty}
</div>

<div class="text-center mb20">
    {$list|raw}
</div>
{include file="manage/create" /}
{/block}


<!-- JS -->
{block name="js"}
    {load href="/static/lib/jquery/jquery.form.js"}
    {load href="/static/lib/jquery/jquery.autofill.min.js"}
    {load href="/static/lib/validator/validator.min.js"}
{/block}
{block name="jscode"}
<script type="text/javascript">
    $(document).ready(function() {

        $('.check-checked').click(function(event) {
            var $url = $(this).data('url');
            // 获取数据表格实例对象
            var myDatatable = $('table.datatable').data('zui.datatable');
            // 获取行选中数据
            var checksStatus = myDatatable.checks;
            if (checksStatus == undefined) {
                return sxj.msg_error('请先选择用户！');
            }
            bootbox.confirm({
                message: "确定要审核选中用户？",
                callback: function(result) {
                    if (result) {
                        sxj.ajax_del($url + '?id=' + checksStatus.checks.toString());
                    }
                }
            });
        });

        $('.check-disable').click(function(event) {
            var $url = $(this).data('url');
            // 获取数据表格实例对象
            var myDatatable = $('table.datatable').data('zui.datatable');
            // 获取行选中数据
            var checksStatus = myDatatable.checks;
            if (checksStatus == undefined) {
                return sxj.msg_error('请先选择用户！');
            }
            bootbox.confirm({
                message: "确定要禁用选中用户？",
                callback: function(result) {
                    if (result) {
                        sxj.ajax_del($url + '?id=' + checksStatus.checks.toString());
                    }
                }
            });
        });

        $('.check-enable').click(function(event) {
            var $url = $(this).data('url');
            // 获取数据表格实例对象
            var myDatatable = $('table.datatable').data('zui.datatable');
            // 获取行选中数据
            var checksStatus = myDatatable.checks;
            if (checksStatus == undefined) {
                return sxj.msg_error('请先选择用户！');
            }
            bootbox.confirm({
                message: "确定要启用选中用户？",
                callback: function(result) {
                    if (result) {
                        sxj.ajax_del($url + '?id=' + checksStatus.checks.toString());
                    }
                }
            });
        });

        // 管理员 重置密码
        $(".manage-repwd").click(function(event) {
            var $url = $(this).data('url'), $id = $(this).data('id');
            bootbox.prompt({
                title: "重置用户密码",
                inputType: 'password',
                callback: function(result) {
                    if (result == null) {
                        return true;
                    }
                    if (result == '') {
                        return sxj.msg_error('请填写内容!');
                    }
                    sxj.ajax_put($url, { id: $id, pwd: result });
                }
            });
        });
    }); 
</script>
{/block}